app.controller('personaleventscontroller', ['$scope', '$parse', '$http', '$rootScope', function($scope, $parse, $http, $rootScope)
{
	$scope.loadingPersonalEvents = true;
	
	/**
	* Get personal events
	*/ 
	$scope.getPersonalEventsCommand = function()
	{
		console.info("getPersonalEventsCommand - called");
		$scope.personalevents = [];
		
		$http.post($scope.servicebase, { "service" : "getPersonalEvents", "userId" : $rootScope.currentUser.Id}).
		success(function(data, status) 
		{
			console.info("getPersonalEventsCommand - call success"); 
			$scope.data = data;
			$scope.result = data; 
			if(data.isFailed == true)
			{
				$scope.setMessageCommand($scope.data.exception, 'danger');
			}
			
			$scope.personalevents = $scope.data.response;
		})
		.
		error(function(data, status) 
		{
			console.error("getPersonalEventsCommand - call failed"); 	
			$scope.loadingEvents = false;
			$scope.data = data || "Request failed";	
			console.error("getPersonalEventsCommand - data : " + $scope.data); 				
		});
	}
	
	/**
	*	Load the personal events component
	*/
	$scope.loadPersonalEventsComponentCommand = function() 
	{
		console.info("loadPersonalEventsComponentCommand - called");
		$scope.personalevents = [];
		$scope.getPersonalEventsCommand();
		$scope.loadingPersonalEvents = false;
	};
	
	$scope.loadPersonalEventsComponentCommand();
}]);